<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:pe="http://primefaces.org/ui/extensions">

    <h:body>

        <ui:composition template="/resources/template/template.xhtml">

            <ui:define name="content">
                <h:form>

                    <p:panel header="BHT Addmission Details" >

                        <h:panelGrid columns="2" >

                            <h:outputLabel value="From Date" />
                            <p:calendar value="#{inwardReportController.fromDate}" styleClass="dateTimePicker"
                                        navigator="true" pattern="yyyy-MMM-dd hh:mm:ss a" ></p:calendar>
                            
                            <h:outputLabel value="To Date" />
                            <p:calendar value="#{inwardReportController.toDate}" styleClass="dateTimePicker"
                                        navigator="true" pattern="yyyy-MMM-dd hh:mm:ss a" ></p:calendar>

                            <p:outputLabel value="Admission Type"/>
                            <p:selectOneMenu value="#{inwardReportController.admissionType}">
                                <f:selectItem itemLabel="All Admission Type"/>
                                <f:selectItems  value="#{inwardReportController.admissionty}" var="myItem" 
                                                itemValue="#{myItem}" itemLabel="#{myItem.name}"></f:selectItems>
                            </p:selectOneMenu>
                            
                            <p:outputLabel value="Without Canceled BHT" />
                            <p:selectBooleanCheckbox value="#{inwardReportController.withoutCancelBHT}" />
                            
                            <p:outputLabel value="Selection Methord" />
                            <p:selectOneRadio value="#{inwardReportController.reportKeyWord.string}" >
                                <f:selectItem itemLabel="All" itemValue="0" />
                                <f:selectItem itemLabel="Not Discharged &amp; Payment Not Finalized" itemValue="1" />
                                <f:selectItem itemLabel="Discharged &amp; Payment Not Finalized" itemValue="2" />
                                <f:selectItem itemLabel="Discharged and Payment Finalized" itemValue="3" />
                                <f:ajax execute="@this" render="@this" />
                            </p:selectOneRadio>
                        </h:panelGrid>

                        <h:panelGrid columns="3">
                            <p:commandButton ajax="false" value="Process" action="#{inwardReportController.fillAdmissionBookNew()}" onclick="onSubmitButton();" ></p:commandButton>
<!--                            <p:commandButton ajax="false" value="Fill All " action="#{inwardReportController.fillAdmissionBook()}" onclick="onSubmitButton();" ></p:commandButton>
                            <p:commandButton ajax="false" value="Fill UnDischarged Only " action="#{inwardReportController.fillAdmissionBookOnlyInward()}" onclick="onSubmitButton();" ></p:commandButton>
                            <p:commandButton ajax="false" value="Fill Discharged Only " action="#{inwardReportController.fillAdmissionBookOnlyDischarged()}" onclick="onSubmitButton();" ></p:commandButton>
                            <p:commandButton ajax="false" value="Fill Discharged and Payment Not Finalized " action="#{inwardReportController.fillAdmissionBookOnlyDischargedNotFinalized()}" onclick="onSubmitButton();" ></p:commandButton>
                            <p:commandButton ajax="false" value="Fill Discharged and Payment Finalized" action="#{inwardReportController.fillAdmissionBookOnlyDischargedFinalized()}" onclick="onSubmitButton();" ></p:commandButton>-->

                            <p:commandButton value="Print" ajax="false" action="#" >
                                <p:printer target="gpBillPreview" ></p:printer>
                            </p:commandButton>

                            <p:commandButton ajax="false" value="Excel" styleClass="noPrintButton" style="float: right;" onclick="onSubmitButton();" >
                                <pe:exporter type="xlsx" target="tbl" fileName="Admission_Detail_by_Admitted_Date"  />
                            </p:commandButton>  
                        </h:panelGrid>
                        <h:panelGrid columns="4">
                            <p:outputLabel value="BHT No" />
                            <p:selectBooleanCheckbox value="#{inwardReportController.bhtNo}" />
                            <p:outputLabel value="Payment Methord" />
                            <p:selectBooleanCheckbox value="#{inwardReportController.paymentMethord}" />
                            <p:outputLabel value="Credit Company" />
                            <p:selectBooleanCheckbox value="#{inwardReportController.creditCompany}" />
                            <p:outputLabel value="Patient Details" />
                            <p:selectBooleanCheckbox value="#{inwardReportController.person}" />
                            <p:outputLabel value="Guardian Details" />
                            <p:selectBooleanCheckbox value="#{inwardReportController.guardian}" />
                            <p:outputLabel value="Room" />
                            <p:selectBooleanCheckbox value="#{inwardReportController.room}" />
                            <p:outputLabel value="Refering Doctor" />
                            <p:selectBooleanCheckbox value="#{inwardReportController.refDoctor}" />
                            <p:outputLabel value="Admit Date" />
                            <p:selectBooleanCheckbox value="#{inwardReportController.addmitDetails}" />
                            <p:outputLabel value="Billed By" />
                            <p:selectBooleanCheckbox value="#{inwardReportController.billedBy}" />
                            <p:outputLabel value="Totals" />
                            <p:selectBooleanCheckbox value="#{inwardReportController.finalBillTotal}" />
                        </h:panelGrid>

                        <h:panelGroup id="gpBillPreview">
                            <p:dataTable id="tbl"  rowStyleClass="#{i.retired ? 'crossLine':''}" 
                                         styleClass="noBorder normalFont" value="#{inwardReportController.patientEncounters}" 
                                         var="i" rowIndexVar="a" >
                                <f:facet name="header">
                                    <h:outputLabel value="Inward Payment Bill Item "/>
                                    <h:outputLabel value="#{i.department.institution.name}"/> 
                                    <h:panelGrid columns="4">
                                        <h:outputLabel value="From  "/>
                                        <h:outputLabel value="#{inwardReportController.fromDate}">
                                            <f:convertDateTime pattern="dd/MM/yy &nbsp; hh:mm:ss a" />
                                        </h:outputLabel>
                                        <h:outputLabel value="To  "/>
                                        <h:outputLabel value="#{inwardReportController.toDate}">
                                            <f:convertDateTime pattern="dd/MM/yy &nbsp; hh:mm:ss a"/>
                                        </h:outputLabel>
                                    </h:panelGrid>
                                </f:facet>

                                <!--                                <p:column headerText="View">
                                                                    <p:commandButton ajax="false" value="View Detail"
                                                                                    action="/inward/inward_bill_intrim_finalized"
                                                                                    actionListener="#{bhtSummeryFinalizedController.createTablesFinalized()}" onclick="onSubmitButton();" >
                                                                        <f:setPropertyActionListener value="#{i}" target="#{bhtSummeryFinalizedController.patientEncounter}"/> 
                                                                    </p:commandButton>
                                                                </p:column>-->

                                <p:column headerText="No">
                                    <f:facet name="header">
                                        <h:outputLabel value="No"/>
                                    </f:facet>
                                    <h:outputLabel value="#{a+1}" ></h:outputLabel>
                                </p:column>

                                <p:column headerText="BHT No" rendered="#{inwardReportController.bhtNo}">
                                    <f:facet name="header">
                                        <h:outputLabel value="BHT No"/>
                                    </f:facet>
                                    <h:outputLabel value="#{i.bhtNo}" ></h:outputLabel>
                                </p:column>

                                <p:column headerText="Room" rendered="#{inwardReportController.room}">
                                    <f:facet name="header">
                                        <h:outputLabel value="Room"/>
                                    </f:facet>
                                    <h:outputLabel value="#{i.currentPatientRoom.roomFacilityCharge.room.name}" >
                                    </h:outputLabel>
                                </p:column>


                                <p:column headerText="Patient Name" rendered="#{inwardReportController.person}">
                                    <f:facet name="header">
                                        <h:outputLabel value="Patient Name"/>
                                    </f:facet>                                    
                                    <h:outputLabel value="#{i.patient.person.name}"  >
                                    </h:outputLabel>
                                </p:column>

                                <p:column headerText="Referring Consultant" rendered="#{inwardReportController.refDoctor}">
                                    <f:facet name="header">
                                        <h:outputLabel value="Referring Consultant"/>
                                    </f:facet>                                    
                                    <h:outputLabel value="#{i.referringDoctor.person.nameWithTitle}"  >
                                    </h:outputLabel>
                                </p:column>

                                <p:column headerText="Admitted By" rendered="#{inwardReportController.billedBy}">
                                    <f:facet name="header">
                                        <h:outputLabel value="Admited By"/>
                                    </f:facet>                                    
                                    <h:outputLabel value="#{i.creater.webUserPerson.name}"  >
                                        <f:convertDateTime pattern="dd/MMM/yyyy - hh:mm:ss a" ></f:convertDateTime>
                                    </h:outputLabel>
                                </p:column>

                                <p:column headerText="Admitted Date" rendered="#{inwardReportController.addmitDetails}">
                                    <f:facet name="header">
                                        <h:outputLabel value="Admited Date"/>
                                    </f:facet>                                    
                                    <h:outputLabel value="#{i.dateOfAdmission}"  >
                                        <f:convertDateTime pattern="dd/MMM/yyyy - hh:mm:ss a" ></f:convertDateTime>
                                    </h:outputLabel>
                                </p:column>
                                
                                <p:column headerText="Admission Created Time" rendered="#{inwardReportController.addmitDetails}">
                                    <f:facet name="header">
                                        <h:outputLabel value="Admission Created Time"/>
                                    </f:facet>                                    
                                    <h:outputLabel value="#{i.createdAt}"  >
                                        <f:convertDateTime pattern="dd/MMM/yyyy - hh:mm:ss a" ></f:convertDateTime>
                                    </h:outputLabel>
                                </p:column>

                                <p:column headerText="Address" rendered="#{inwardReportController.person}">
                                    <f:facet name="header">
                                        <h:outputLabel value="Address"/>
                                    </f:facet>                                    
                                    <h:outputLabel value="#{i.patient.person.address}"  >
                                    </h:outputLabel>
                                </p:column>

                                <p:column headerText="Phone" rendered="#{inwardReportController.person}">
                                    <f:facet name="header">
                                        <h:outputLabel value="Phone"/>
                                    </f:facet>                                    
                                    <h:outputLabel value="#{i.patient.person.phone}"  >
                                    </h:outputLabel>
                                </p:column>

                                <p:column headerText="Guardian Name" rendered="#{inwardReportController.guardian}">
                                    <f:facet name="header">
                                        <h:outputLabel value="Guardian Name"/>
                                    </f:facet>                                    
                                    <h:outputLabel value="#{i.guardian.nameWithTitle}"  >
                                    </h:outputLabel>
                                </p:column>

                                <p:column headerText="Guardian Address" rendered="#{inwardReportController.guardian}">
                                    <f:facet name="header">
                                        <h:outputLabel value="Guardian Address"/>
                                    </f:facet>                                    
                                    <h:outputLabel value="#{i.guardian.address}"  >
                                    </h:outputLabel>
                                </p:column>

                                <p:column headerText="Guardian Phone" rendered="#{inwardReportController.guardian}">
                                    <f:facet name="header">
                                        <h:outputLabel value="Guardian Phone"/>
                                    </f:facet>                                    
                                    <h:outputLabel value="#{i.guardian.phone}"  >
                                    </h:outputLabel>
                                </p:column>

                                <p:column headerText="Payment Method" rendered="#{inwardReportController.paymentMethord}">
                                    <f:facet name="header">
                                        <h:outputLabel value="Payment Method"/>
                                    </f:facet>                                    
                                    <h:outputLabel value="#{i.paymentMethod}"  >
                                    </h:outputLabel>
                                </p:column>

                                <p:column headerText="MemberShip Scheme" rendered="#{inwardReportController.person}">
                                    <f:facet name="header">
                                        <h:outputLabel value="MemberShip Scheme"/>
                                    </f:facet>                                    
                                    <h:outputLabel  value="#{i.patient.person.membershipScheme.name}" >
                                    </h:outputLabel>
                                </p:column>

                                <p:column headerText="Credit Company Name" rendered="#{inwardReportController.creditCompany}">
                                    <f:facet name="header">
                                        <h:outputLabel value="Credit Company Name"/>
                                    </f:facet>                                    
                                    <h:outputLabel  value="#{i.creditCompany.name}" >
                                    </h:outputLabel>
                                </p:column>


                                <p:column styleClass="averageNumericColumn"  headerText="Total" rendered="#{inwardReportController.finalBillTotal}">
                                    <h:outputLabel value="#{i.finalBill.netTotal}">
                                        <f:convertNumber pattern="#,##0.00" />
                                    </h:outputLabel>
                                    <f:facet name="footer">
                                        <h:outputLabel value="#{inwardReportController.netTotal}">
                                            <f:convertNumber pattern="#,##0.00" />
                                        </h:outputLabel>
                                    </f:facet>
                                </p:column>

                                <p:column styleClass="averageNumericColumn"  headerText="Discount" rendered="#{inwardReportController.finalBillTotal}">
                                    <h:outputLabel value="#{i.finalBill.discount}">
                                        <f:convertNumber pattern="#,##0.00" />
                                    </h:outputLabel>
                                </p:column>
                                
                                <p:column styleClass="averageNumericColumn"  headerText="Paid" rendered="#{inwardReportController.finalBillTotal}">
                                    <h:outputLabel value="#{i.paidByCreditCompany+i.finalBill.paidAmount}">
                                        <f:convertNumber pattern="#,##0.00" />
                                    </h:outputLabel>
                                    <f:facet name="footer">
                                        <h:outputLabel value="#{inwardReportController.netPaid}">
                                            <f:convertNumber pattern="#,##0.00" />
                                        </h:outputLabel>
                                    </f:facet>
                                </p:column>

                                <p:column styleClass="averageNumericColumn" headerText="Due" rendered="#{inwardReportController.finalBillTotal}">
                                    <h:outputLabel value="#{i.finalBill.netTotal-(i.paidByCreditCompany+i.finalBill.paidAmount)}">
                                        <f:convertNumber pattern="#,##0.00" />
                                    </h:outputLabel>
                                    <f:facet name="footer">
                                        <h:outputLabel value="#{inwardReportController.netTotal-inwardReportController.netPaid}">
                                            <f:convertNumber pattern="#,##0.00" />
                                        </h:outputLabel>
                                    </f:facet>
                                </p:column>

                            </p:dataTable>
                        </h:panelGroup>
                    </p:panel>
                </h:form>


            </ui:define>


        </ui:composition>

    </h:body>
</html>
